package com.timeDeal.service;

import com.timeDeal.bean.ShijianchushouBean;
import com.timeDeal.util.DButil;

import java.sql.*;

/**
 * Created by wzq on 2016/9/12 0012.
 */
public class ChushouService {
    public boolean addItem(ShijianchushouBean sjcsb){
        Connection con = DButil.getConnection() ;
        String sql = "INSERT INTO shijianchushou (shijianchushouid,jineng,quyu,beizhu,kaishiriqi,jieshuriqi,zhuangtai,yunxujingbiao,jingbiaoriqi,choulaoxiaxian,choulao,fabushijian,mingcheng,redu,jiafangid)"
        +"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) " ;
        PreparedStatement preparedStatement = null ;
        ResultSet resultSet = null  ;
        ShijianchushouBean shijianchushouBean = sjcsb ;
        boolean result =true ;
        try {
            preparedStatement = con.prepareStatement(sql) ;
            sjcsb.setShijianchushouid(DButil.getZhuJianMax("shijianchushouid","shijianchushou"));
            preparedStatement.setInt(1,sjcsb.getShijianchushouid());
            preparedStatement.setString(2,sjcsb.getJineng());
            preparedStatement.setString(3,sjcsb.getQuyu());
            preparedStatement.setString(4,sjcsb.getBeizhu());
            preparedStatement.setDate(5,sjcsb.getKaishiriqi());
            preparedStatement.setDate(6,sjcsb.getJieshuriqi()) ;
            preparedStatement.setString(7,sjcsb.getZhuangtai());
            preparedStatement.setString(8,sjcsb.getYunxujingbiao());
            preparedStatement.setDate(9,sjcsb.getJingbiaoriqi());
            preparedStatement.setInt(10,sjcsb.getChoulaoxiaxian());
            preparedStatement.setInt(11,sjcsb.getChoulao());
            preparedStatement.setString(12,String.valueOf(System.currentTimeMillis()));
            preparedStatement.setString(13,sjcsb.getShijianchushoumingcheng());
            preparedStatement.setInt(14,0);
            preparedStatement.setInt(15,sjcsb.getJiafangid());

            preparedStatement.execute();

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
                try {
                 if(preparedStatement!=null)
                        preparedStatement.close();
                    if(resultSet!=null)
                             resultSet.close();
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
        }
        return result ;
    }

}
